package com.pb.infra.auth.controller;

import com.pb.infra.oth.entity.common.Page;
import com.pb.infra.oth.entity.common.Result;
import com.pb.infra.auth.entity.pbsys.MetaPriviPasswdPolicy;
import com.pb.infra.auth.service.MetaPriviPasswdPolicyService;
import com.pb.infra.oth.util.Constant;
import com.pb.infra.oth.util.StringUtil;
import com.pb.infra.oth.util.SysLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
/**
 * 系统密码策略标识
 *
 * @Author:liudebao
 * @Date: 2020/12/25
 */
@Slf4j
@RestController
@RequestMapping("v1/system/pd")
public class MetaPriviPasswdController {

    /**
     * 日志操作表
     */
    private static final String TABLE_NAME = "META_PRIVI_PASSWD_POLICY";

    /**
     * 日志操作功能名
     */
    private static final String OPERATION_MENU = "系统密码策略";

    /**
     * 业务逻辑对象
     */
    @Resource
    private MetaPriviPasswdPolicyService metaPriviPasswdPolicyService;

    /**
     * 查询系统密码策略
     * @param paramMap 请求参数
     * @param page
     * @return Result 返回数据
     */
    @GetMapping("select")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.QUERY, menuName = OPERATION_MENU)
    public Result select(@RequestParam Map<String, Object> paramMap, Page page) {
        return metaPriviPasswdPolicyService.select(paramMap,page);
    }

    /**
     *查询密码规则
     * @param paramMap 请求参数
     * @return Result 返回数据
     */
    @GetMapping("selectRule")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.QUERY, menuName = OPERATION_MENU)
    public Result selectRule(@RequestParam Map<String, Object> paramMap) {
        return metaPriviPasswdPolicyService.selectRule();
    }

    /**
     * 新建系统密码策略
     *
     * @param metaPriviPasswdPolicy 请求参数
     * @return Result 返回数据
     */
    @PostMapping("insert")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.ADD, menuName = OPERATION_MENU)
    public Result insert(@RequestBody MetaPriviPasswdPolicy metaPriviPasswdPolicy) {
        Map<String, Object> map1 = metaPriviPasswdPolicyService.insert(metaPriviPasswdPolicy);
        if (map1 != null && !Constant.OK.equals(map1.get("code").toString()) && !StringUtil.isEmpty(map1.get("msg"))) {
            return Result.error(map1.get("code").toString(), map1.get("msg").toString());
        } else {
            return Result.ok(map1);
        }
    }


    /**
     * 修改系统密码策略
     *
     * @param metaPriviPasswdPolicy 请求参数
     * @return Result 返回数据
     */
    @PostMapping("update")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.MOD, menuName = OPERATION_MENU)
    public Result update(@RequestBody MetaPriviPasswdPolicy metaPriviPasswdPolicy) {
        metaPriviPasswdPolicyService.update(metaPriviPasswdPolicy);
        return Result.OK_EMPTY;
    }

    /**
     * 删除系统密码策略
     *
     * @param paramMap 请求参数
     * @return Result 返回数据
     */
    @PostMapping("delete")
    @SysLog(tableName = TABLE_NAME, action = Constant.ACTION_NAME.DEL, menuName = OPERATION_MENU)
    public Result delete(@RequestBody List<String> paramMap) {
        metaPriviPasswdPolicyService.delete(paramMap);
        return Result.OK_EMPTY;
    }
}

